/**
 * Copyright (c) 2009-2011, chunquedong(YangJiandong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * History:
 *     2010-05-05  Jed Young  Creation
 */
package chunmap.app.bench;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;


public class ComponentUtils {
	public static void bindEvent(final OperateManager mapboxListener,Component component) {
		component.addMouseWheelListener(new MouseWheelListener() {
			@Override
			public void mouseWheelMoved(MouseWheelEvent e) {
				mapboxListener.onEvent(e, EventType.MouseWheel);
			}
		});
		component.addMouseListener(new MouseListener() {
	
			@Override
			public void mouseClicked(MouseEvent e) {
				if(e.getClickCount()>1){
					mapboxListener.onEvent(e, EventType.MouseDoubleClick);
				}else{
					mapboxListener.onEvent(e, EventType.MouseClik);
				}
			}
	
			@Override
			public void mouseEntered(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseEntered);
			}
	
			@Override
			public void mouseExited(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseExited);
			}
	
			@Override
			public void mousePressed(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseDown);
			}
	
			@Override
			public void mouseReleased(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.KeyUp);
			}
	
		});
		component.addMouseMotionListener(new MouseMotionListener() {
			@Override
			public void mouseDragged(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseDragged);
			}
	
			@Override
			public void mouseMoved(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseMove);
			}
		});
		component.addKeyListener(new KeyListener() {
	
			@Override
			public void keyPressed(KeyEvent e) {
				mapboxListener.onEvent(e, EventType.KeyDown);
			}
	
			@Override
			public void keyReleased(KeyEvent e) {
				mapboxListener.onEvent(e, EventType.KeyUp);
			}
	
			@Override
			public void keyTyped(KeyEvent e) {
				mapboxListener.onEvent(e, EventType.Unknow);
			}
		});
	}
}